/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.myapp.struts;

import Entities.Article;
import Model.ArticleModel;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author AMENOSA
 */
public class articleActionNoForm extends org.apache.struts.action.Action {

    /*
     * forward name="success" path=""
     */
    private static final String SUCCESS = "success";

    /**
     * This is the action called from the Struts framework.
     *
     * @param mapping The ActionMapping used to select this instance.
     * @param form The optional ActionForm bean for this request.
     * @param request The HTTP Request we are processing.
     * @param response The HTTP Response we are processing.
     * @throws java.lang.Exception
     * @return
     */
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        String action = request.getParameter("action");
        ArticleModel articleModel = new ArticleModel();
        if (action.equals("deleteAll")) {
            String ids = request.getParameter("id");
            request.setAttribute("articleIds", ids);
            if (articleModel.deleteNArticle(ids) > 0) {
                return mapping.findForward("success");
            }
        } else if (action.equals("edit")) {
            int id = Integer.parseInt(request.getParameter("id").toString());
            Article article = articleModel.getArticle(id);
            request.setAttribute("articleEdit", article);
//            article.setCategory_id(1);
//            article.setTitle("");
//            article.setContent("");
//            article.setRate(0);
//            article.setStatus(false);
            return mapping.findForward("edit");
        }
        return mapping.findForward("error");
    }
}
